package com.zhouzj.task.consumer;

import com.zhouzj.task.consumer.rpc.ConsumerComponent;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * @Author: zhouzhijun
 * @Date: 2021/7/21 15:12
 */
public class ConsumerApplication {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();

        //创建线程池进行调用服务
        ConsumerComponent service = context.getBean(ConsumerComponent.class);
        Executor executor1 = Executors.newFixedThreadPool(5);
        executor1.execute(new Consume(service, "A"));

        Executor executor2 = Executors.newFixedThreadPool(5);
        executor2.execute(new Consume(service, "B"));

        Executor executor3 = Executors.newFixedThreadPool(5);
        executor3.execute(new Consume(service, "C"));

    }

    @Configuration
    @PropertySource("classpath:/dubbo.properties")
    @ComponentScan("com.zhouzj.task")
    @EnableDubbo
    static class ConsumerConfiguration {
    }
}
